$fa=2;
$fs=0.2;
th = 2.4;        // 厚度
high = 150+81.6; // 高度
width = 25;      // 高度
angle = atan(1/sqrt(2)); // 35.3
//angle = 20;
camera_horizontal_to_cube_corner = 57.7;
camera_to_cube_corner = 100;
m3_hole_through = 3.4;// m3通孔
m4_hole_through = 4.6;// m4通孔
m3_nut_hole_d = 4.4;  // 滚花螺母孔径，需要比滚花螺母直径略小一点
base_size = 30;  // 底座尺寸
camera_hole_d = 14.6+0.25;// 镜头直径

module round_cube(x,y,z,radius){
    translate([-x/2, -y/2, -z/2])
    hull(){
        translate([radius,radius,0])cylinder(h=z,r=radius);
        translate([-radius+x,radius,0])cylinder(h=z,r=radius);
        translate([radius,-radius+y,0])cylinder(h=z,r=radius);
        translate([-radius+x,-radius+y,0])cylinder(h=z,r=radius);
    }
}

union()
{
    // 立柱
    difference()
    {
        union()
        {
            translate([0,-width/2,0])     cube([high,width,th]);
            translate([0,-width/2,0])     cube([high,th,width/2]);
            translate([0,width/2-th,0])   cube([high,th,width/2]);
        }
        translate([high+17.1,0,15]) rotate([0,angle-90,0]) 
            cube([80,80,20],center=true);
    }
    // 底座
    difference()
    {
        translate([0,-base_size/2,0])cube([4,base_size,base_size]);
        translate([0,0,base_size/2+6]) rotate([0,90,0]) 
            cylinder(20,d=m4_hole_through,center=true);
        translate([0,0,base_size/2-6]) rotate([0,90,0]) 
            cylinder(20,d=m4_hole_through,center=true);
    }
    // 摄像头夹具
    translate([high,0,15]) rotate([0,angle-90,0]) 
    {
        difference()
        {
            round_cube(30,30,8,10);
            cube([16,3.5,20],center=true);
            cylinder(20,d=camera_hole_d,center=true);
            translate([0,10,0]) rotate([90,0,0]) 
                  cylinder(20,d=m3_nut_hole_d,center=true);
        }
    }
}



